export default {
  data () {
    return {
			formPath: '' as string,
			formData: {} as object,
			handing: false as boolean,
			params: {},
			actCol: '' as string
    }
  },
	methods: {
		submit(){
      console.log(this.formData)
			!this.handing && this.$refs.uForm.validate().then((valid: boolean) => {
        if(valid && this.beforeSubmit()){
					this.formData.id ? this.put() : this.save()
				}
			}).catch((errors: object[]) => {
				uni.$u.toast(errors[0].message)
			})
		},
		save(){
			this.handing = true
			uni.$u.http.post(this.formPath, this.formData).then((data: any)=>{
				this.handing = false
				this.afterSubmit(data)
			}).catch(()=>{
				this.handing = false
			})
		},
		put(){
			this.handing = true
			uni.$u.http.put(this.formPath, this.formData).then((data: any) => {
				this.handing = false
				this.afterSubmit(data)
			}).finally(()=>{
				this.handing = false
			}).catch(() => {
			})
		},
		ok() {
			uni.$u.http.post(this.formPath, this.params).then((data: any)=>{
				this.afterSubmit(data)
			}).catch(()=>{})
		},
		beforeSubmit(){
			return true;
		},
		afterSubmit(res: object){},
		chooseLocation(name: string){
			uni.chooseLocation({
				success(res){
					this.formData[name] = res.address
				}
			})
		}
	}
}